package com.hqx.shiro.base;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;

/**
 *
 * Created by PH on 2019/4/1.
 */
@Getter
@Setter
public class BaseResult {

	/**
	 * 密码错误
	 */
	public static final String wrong_password = "-2";
	/**
	 * 用户已存在
	 */
	public static final String HAS_USER = "-3";

	/**
	 * 用户未认证
	 */
	public static final String NOT_AUTH = "-4";

	/**
	 * 用户不存在
	 */
	public static final String NO_USER = "-5";

	/**
	 * 没有相关权限
	 */
	public static final String NO_PERMISSION = "-6";
	/**
	 * 成功的code
	 */
	public static final Integer SUCCESS_CODE = 200;


	private Object data;

	private String msg;

	private Integer code ;

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public static BaseResult success() {

		return success(null);
	}

	public static BaseResult success(Object object) {
		BaseResult baseResult = new BaseResult();
		baseResult.setCode(200);
		if(object == null){
			object = new HashMap<> (0);
		}
		baseResult.setData(object);
		return baseResult;
	}
	public static BaseResult success(String msg,Object object) {
		BaseResult baseResult = new BaseResult();
		baseResult.setCode(200);
		baseResult.setMsg(msg);
		baseResult.setData(object);
		return baseResult;
	}

	public static BaseResult error(Integer code, String msg) {

		BaseResult baseResult = new BaseResult();
		baseResult.setCode(code);
		baseResult.setMsg(msg);
		return baseResult;
	}

	public static BaseResult error(String msg) {
		BaseResult baseResult = new BaseResult();
		baseResult.setCode(-1);
		baseResult.setMsg(msg);
		return baseResult;
	}

}